package gov.dhs.cis.soa.data;

import gov.dhs.cis.soa.Utils;
import gov.dhs.cis.soa.Constants.EntityType;

public class EntitiesReferences extends AbstractSOAData {
	public int id;
	public int entityid;
	public String entitytype;
	public String refQualifier = "NONE";
	public int refid;
	public String reftype;
	public transient String srcEntityHashableId;
	public transient String refEntityHashableId;

	@Override
	public String toString() {
		return "EntitiesRefs [ entityid = " + entityid + ", Type = " + entitytype + ", Qual=" + refQualifier + ", refid = " + refid + ", reftype=" + reftype + "]";
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		EntitiesReferences other = (EntitiesReferences) obj;
		if (refid == other.refid && entityid == other.entityid && refid == other.refid
				&& entitytype.equalsIgnoreCase(other.entitytype) && reftype.equalsIgnoreCase(other.reftype))
			return true;
		return false;
	}
	
	public static EntitiesReferences getNewEntitiesReference(AbstractSOAData srcEntity, AbstractSOAData refEntity, String refEntQual) {
		//int entityid, EntityType entityType, int refId, EntityType refEntityType, String refEntQual - old params - RSingh 04/22/10
		EntitiesReferences refItem = null;
		
		refItem = new EntitiesReferences();
		refItem.id = Utils.getNextId();
		refItem.entityid = (int)srcEntity.getId();
		refItem.entitytype = srcEntity.getUMLType().toString();
		refItem.refQualifier = Utils.isEmpty(refEntQual) ? null : refEntQual.trim();
		refItem.refid = (int)refEntity.getId();
		refItem.reftype = refEntity.getUMLType().toString();
		
		refItem.srcEntityHashableId = srcEntity.getHashableId();
		refItem.refEntityHashableId = refEntity.getHashableId();
		return refItem;
	}
	
//	public static String getUMLId(int entityId) {
//		return EntityType.EREF + "_" + entityId;
//	}
	
	@Override
	public long getId() {
		return id;
	}
	@Override
	public String getHashableId() {
		String ret = srcEntityHashableId + " " + (refQualifier == null ? "" : refQualifier) + refEntityHashableId;
		return ret;
	}

	@Override
	public EntityType getUMLType() {
		return EntityType.EREF;
	}
}
